/*
 * @desc:
 * @author: mao
 * @version: 1.0
 * @Date: 2024-04-30 14:20:13
 */
import { fileURLToPath, URL } from "node:url";
import { defineConfig } from "vite";
import vue from "@vitejs/plugin-vue";
import AutoImport from "unplugin-auto-import/vite";
import legacy from "@vitejs/plugin-legacy";
import autoprefixer from "autoprefixer";
import Components from "unplugin-vue-components/vite";
import { AntDesignVueResolver } from "unplugin-vue-components/resolvers";

// https://vitejs.dev/config/
export default defineConfig({
    base: "/",
    plugins: [
        vue(),
        Components({
            resolvers: [AntDesignVueResolver({ importStyle: false })],
        }),
        AutoImport({
            include: [
                /\.[tj]sx?$/, // .ts, .tsx, .js, .jsx
                /\.vue$/,
                /\.vue\?vue/, // .vue
                /\.md$/, // .md
            ],
            imports: ["vue", "vue-router", "pinia"],
            dts: "./auto-imports.d.ts",
            eslintrc: {
                enabled: false, // Default `false`
                filepath: "./.eslintrc-auto-import.json", // Default `./.eslintrc-auto-import.json`
                globalsPropValue: true, // Default `true`, (true | false | 'readonly' | 'readable' | 'writable' | 'writeable'),
            },
        }),
        legacy({
            targets: ["ie >= 11"],
            additionalLegacyPolyfills: ["regenerator-runtime/runtime"],
        }),
    ],
    resolve: {
        alias: {
            "@": fileURLToPath(new URL("./src", import.meta.url)),
        },
    },
    css: {
        preprocessorOptions: {
            scss: {
                additionalData: `@import "@/styles/_index.scss";`,
            },
        },
        postcss: {
            plugins: [autoprefixer()],
        },
    },
    server: {
        hmr: true,
        port: 9000,
        host: "0.0.0.0",
        proxy: {
            // 字符串简写写法
            // '/columns': 'http://localhost:4567/foo',
            // 选项写法
            // '/nbd-video-edit-service': {
            //     target: 'ws://192.168.21.225:8091/nbd-video-edit-service',
            //     changeOrigin: true,
            //     rewrite: (path) => path.replace(/^\/nbd-video-edit-service/, '')
            // }
            "/c/": "http://172.19.30.24:8119",
            "/mediaresource-manage-service/": {
                target: "http://10.20.5.34:32310",
                changeOrigin: true,
            },
            "/mediaresourcelib-base-lib/": {
                target: "http://10.20.5.34:32310",
                changeOrigin: true,
            },
            "/mediaresourcelib-file-manager/": {
                target: "http://10.20.5.34:32310",
                changeOrigin: true,
            },
            "/usersys-auth/": {
                target: "http://10.20.5.34:32310",
                changeOrigin: true,
            },
            "/usersys-app/": {
                target: "http://10.20.5.34:32310",
                changeOrigin: true,
            },
            "/mediaresourcelib-alliancemanagement-service/": {
                target: "http://10.20.5.34:32310",
                changeOrigin: true,
            },
            "/mediaresourcelib-datastatistics-service/": {
                target: "http://10.20.5.34:32310",
                changeOrigin: true,
            },
            "/mediaresourcelib-common-cms/": {
                target: "http://10.20.5.34:32310",
                changeOrigin: true,
            },
            "/mediaslib-service/": {
                target: "http://192.168.21.198:8092",
                changeOrigin: true,
            },
        },
    },
    build: {
        // polyfillDynamicImport:Boolean(VITE_LEGACY) , //是否打包兼容低版本浏览器
        target: "es2015",
        assetsDir: "static",
        outDir: "dist",
        minify: "esbuild",
        // terserOptions: {
        //     compress: {
        //         // drop_console: true,
        //         drop_debugger: true,
        //     },
        // },
        rollupOptions: {},
    },
});
